// SeamAway Rev.A, by Dave Bushnell
// ZBrush ZScript v1.23b 

[varDef,DocWidth]
[varDef,DocHeight]
[varDef,DocMidX]
[varDef,DocMidY]
[varDef,GradPos,0]
[varDef,ClonerInited,0]
[varDef,DrawRadius]
[varDef,FadeWidth]
[varDef,ThisTexture]
[varDef,SecondTexture]
[varDef,HybridTexture,0]
[varDef,HorizMethod,0]
[varDef,VertMethod,0]
[varDef,SettingsData(11)]
[varDef,MethodNameH(4)]
[varSet,MethodNameH(0),"MethodH1"][varSet,MethodNameH(1),"MethodH2"][varSet,MethodNameH(2),"MethodH3"][varSet,MethodNameH(3),"MethodH4"]
[varDef,MethodNameV(4)]
[varSet,MethodNameV(0),"MethodV1"][varSet,MethodNameV(1),"MethodV2"][varSet,MethodNameV(2),"MethodV3"][varSet,MethodNameV(3),"MethodV4"]
[varDef,PosTransX(4)]
[varSet,PosTransX(0),-1][varSet,PosTransX(1),0][varSet,PosTransX(2),1][varSet,PosTransX(3),0]
[varDef,PosTransY(4)]
[varSet,PosTransY(0),0][varSet,PosTransY(1),-1][varSet,PosTransY(2),0][varSet,PosTransY(3),1]
[varDef,ShowMessage,1]
[varDef,WorkLayer(2)]
[varDef,VerifyResult,0]
[varDef,SectionText,"                              Modifiers                              "]
[fontSetSizeSmall][varSet,ButtonWidth,[textCalcWidth,[var,SectionText]]+3][FontSetSizeMedium]
[varSet,ButtonWidth2,ButtonWidth/2-64]

[PenMove,0,2][Image,SeamAway.psd][PenMove,15,3][ibutton,"Return to Menu","Load the Script Selection Interface",[fileNameSetNext,"DefaultZScript.txt"][iPress,7427]]
[penMove,0,12]
[pd][penMove,,6][penMoveCenter][penMove,-ButtonWidth/2][image,SAreflect.psd,1]
[penMove,6][iButton," Method 1 ","Use Method 1",
	[RoutineCall,MakeItHappen,0,0]
	[RoutineCall,VerifyUndo]
,,ButtonWidth2] // end iButton
[penMoveCenter][penMove,10][image,SAshift.psd,1]
[penMove,6][iButton," Method 2 ","Use Method 2",
	[RoutineCall,MakeItHappen,1,1]
	[RoutineCall,VerifyUndo]
,,ButtonWidth2] // end iButton
[penMoveCenter][penMove,54-(ButtonWidth/2),17]Fade-in a reflection [penMoveCenter][penMove,64]Fade-in a shifted image [penMoveCenter][penMove,54-(ButtonWidth/2),15]of the same texture. [penMoveCenter][penMove,64]of the same texture.
[penMove,,8][penMoveCenter][penMove,-ButtonWidth/2][image,SA2ndtexture.psd,1]
[penMove,6][iButton," Method 3 ","Use Method 3",
	[RoutineCall,MakeItHappen,2,2]
	[RoutineCall,VerifyUndo]
,,ButtonWidth2] // end iButton
[penMoveCenter][penMove,10][image,SAcolor.psd,1]
[penMove,6][iButton," Method 4 ","Use Method 4",
	[RoutineCall,MakeItHappen,3,3]
	[RoutineCall,VerifyUndo]
,,ButtonWidth2] // end iButton
[penMoveCenter][penMove,54-(ButtonWidth/2),17]Fade-in another [penMoveCenter][penMove,64]Fade-in the selected [penMoveCenter][penMove,54-(ButtonWidth/2),15]texture. [iSlider," =",3,1,0,[iGetMax,texture:itemInfo],"Item-Info value of secondary texture",
,,[textCalcWidth,"00000"]] // end iSlider
[iButton,"P","Use Current Texture as the Secondary Texture",
	[if,[iGetMax,-1]<[iGet,texture:itemInfo],[iSetMax,-1,[iGet,texture:itemInfo]]]
	[iSet,-1,[iGet,texture:itemInfo]]
] // end iButton
[penMoveCenter][penMove,64]color.
[penMove,,8]
[penMoveCenter][penMove,-ButtonWidth/2]
[iSlider," Fade-in Width ",25,1,2,100,"Width of the Fade-In texture or color, as percentage",,,ButtonWidth]%
[penMove,0,2][penMoveCenter][penMove,-ButtonWidth/2][iButton," Show and Tell ","Brief Tutorial",
	[routineCall,storeSettings]
	[Note,"This ZScript takes a single texture and makes it seamlessly tileable, so you can tile it horizontally and vertically without seeing an abrupt seam.",,15]
	[Note,"You can do this using one of four methods. All four methods 'fade in' information at the edges.",,-1]
	[Note,"\n\nWhen finished, you can add the new seamless texture to your texture palette and continue working.",,15]
	
	[Note,"\Cffa000Method 1\Cc0c0c0 fades in a reflection of the same texture at the right and bottom edges.",zscript:method1,10]
	[Note,"Choose a texture and press the \Cffa000Method 1\Cc0c0c0 button.",28601,-1]
	[Note,,zscript:method1,12]
	[iSet,texture:itemInfo,1]
	[routineCall,MakeItHappen,0,0]
	[Note,"This texture can now be added to the Texture palette and tiled seamlessly.",1004,12]
	[iKeyPress,'N',[routineCall,VerifyUndo]]
	
	[Note,"\Cffa000Method 2\Cc0c0c0 fades in the same texture, shifted by half its width and height, at all four edges.",zscript:method2,10]
	[iSet,texture:itemInfo,1]
	[routineCall,MakeItHappen,1,1]
	[Note,"This texture can now be added to the Texture palette and tiled seamlessly.",1004,12]
	[iKeyPress,'N',[routineCall,VerifyUndo]]
	
	[Note,"\Cffa000Method 3\Cc0c0c0 fades in another texture at all four edges.",zscript:method3,11]
	[Note,"The secondary texture can be chosen by matching the \Cffa000=\Cc0c0c0 slider to the Texture:Item Info slider,",texture:itemInfo,-1]
	[Note," or by simply selecting it and pressing the small \Cffa000P\Cc0c0c0 button.",zscript:=,-1]
	[Note,,zscript:p,18]
	[iSet,texture:itemInfo,1]
	[iSet,zscript:=,2]
	[routineCall,MakeItHappen,2,2]
	[Note,"This texture can now be added to the Texture palette and tiled seamlessly.",1004,12]
	[iKeyPress,'N',[routineCall,VerifyUndo]]
	
	[iColorSet,0,255,255]
	[Note,"\Cffa000Method 4\Cc0c0c0 fades in the the selected color at all four edges.",zscript:method4,-1]
	[Note,,3329,12]
	[iSet,texture:itemInfo,1]
	[routineCall,MakeItHappen,3,3]
	[Note,"This texture can now be added to the Texture palette and tiled seamlessly.",1004,12]
	[iKeyPress,'N',[routineCall,VerifyUndo]]
	[routineCall,RecallSettings]
,0,ButtonWidth] // end iButton Show and Tell
[pd][penMove,0,6]
[penMoveCenter][PenMove,-ButtonWidth/2][FontSetSizeSmall][sectionBegin,[var,SectionText]][pd][penMove,0,6]
[penMoveCenter][penMove,-ButtonWidth/2][iButton," Make It Seamless ","Make the texture seamless, using the methods selected below",
	[RoutineCall,MakeItHappen,HorizMethod,VertMethod]
	[RoutineCall,VerifyUndo]	
,,ButtonWidth*.6] // end iButton
[iSwitch," Hide Confirm Message ",0,"Hide 'Okay To Grab' Message (if pressed)",
	[varSet,ShowMessage,0]
,
	[varSet,ShowMessage,1]
,0,ButtonWidth*.4] // end iSwitch
[varSet,ModDescWidth,[TextCalcWidth,"Horizontal: "]][varSet,ModSwitchWidth,(ButtonWidth-ModDescWidth)/5]
[pd][penMoveCenter][penMove,-ButtonWidth/2,8]Horizontal: [penMove,,-5][iSwitch," None ",0,"No Horizontal Effect",
	[varSet,HorizMethod,-1]
	[iUnPress,1][iUnPress,2][iUnPress,3][iUnPress,4]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 1 ",1,"Use Method 1 (reflect same texture)",
	[varSet,HorizMethod,0]
	[iUnPress,1][iUnPress,2][iUnPress,3][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 2 ",0,"Use Method 2 (shift same texture)",
	[varSet,HorizMethod,1]
	[iUnPress,1][iUnPress,2][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 3 ",0,"Use Method 3 (shift secondary texture)",
	[varSet,HorizMethod,2]
	[iUnPress,1][iUnPress,-3][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 4 ",0,"Use Method 4 (color)",
	[varSet,HorizMethod,3]
	[iUnPress,-4][iUnPress,-3][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[pd][penMoveCenter][penMove,-ButtonWidth/2,8]Vertical: [penMove,,-5]
[penMoveCenter][penMove,-ButtonWidth/2][penMove,ModDescWidth]
[iSwitch," None ",0,"No Vertical Effect",
	[varSet,VertMethod,-1]
	[iUnPress,1][iUnPress,2][iUnPress,3][iUnPress,4]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 1 ",1,"Use Method 1 (reflect same texture)",
	[varSet,VertMethod,0]
	[iUnPress,1][iUnPress,2][iUnPress,3][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 2 ",0,"Use Method 2 (shift same texture)",
	[varSet,VertMethod,1]
	[iUnPress,1][iUnPress,2][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 3 ",0,"Use Method 3 (shift secondary texture)",
	[varSet,VertMethod,2]
	[iUnPress,1][iUnPress,-3][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch
[iSwitch," Method 4 ",0,"Use Method 4 (color)",
	[varSet,VertMethod,3]
	[iUnPress,-4][iUnPress,-3][iUnPress,-2][iUnPress,-1]
,,,ModSwitchWidth] // end iSwitch


[penMoveCenter][penMove,-buttonWidth/2]
[sectionEnd][FontSetSizeMedium][pd]
\C00e0e0About This ZScript:
\Cc0c0c0This ZScript can be loaded at any time while you're working. It hides your current layers and draws the currently-selected texture on a new layer. Then it adjusts the edges of the texture to make it seamlessly tileable.

It does this by "fading in" image information at the edges, from other parts of the texture, from another texture, or from a color.

\Cffa000Method 1\Cc0c0c0 fades in a reflection of the same texture at the right edge and at the bottom.

\Cffa000Method 2\Cc0c0c0 fades in the same texture, shifted by half its width and height, at all four edges.

\Cffa000Method 1\Cc0c0c0 fades in another texture at all four edges. Choose the texture by adjusting the \Cffa000=\Cc0c0c0 slider to match that texture's [buttonFind,texture:itemInfo,"Item Info"] number, or by selecting that texture and pressing the small \Cffa000P\Cc0c0c0 button.

\Cffa000Method 1\Cc0c0c0 fades in the selected color at all four edges.

Choose the width of the fade-in value by adjusting the \Cffa000Fade-In Width\Cc0c0c0 slider.

The \Cffa000Show and Tell\Cc0c0c0 button gives you a brief tutorial on how this ZScript is used.

\C00e0e0About the Modifiers:
\Cc0c0c0You can select a different method for the horizontal and vertical fading by pressing the appropriate buttons. Choose \Cffa000None\Cc0c0c0 to leave the horizontal or vertical edges unchanged.

Press the \Cffa000Hide Confirm Message\Cc0c0c0 switch to inhibit the confirmation message that normally appears after drawing.

[fontSetSizeSmall][FontSetOpacity,.5]SeamAway Revision A, created by Dave Bushnell


// ========================= ROUTINES FOLLOW

[RoutineDef,MakeItHappen,
	[varSet,ThisTexture,[iGet,texture:itemInfo]]
	[if,ThisTexture=0,
		[if,[MessageYesNo,"You have no texture selected. Continue anyway?","No texture selected."],,[exit]]
	] // end if
	[RoutineCall,StoreSettings]
	[varSet,SecondTexture,[iGet,zscript:=]]
	[varSet,docWidth,document:modifiers:width]
	[varSet,docHeight,document:modifiers:height]
	[varSet,docMidX,docWidth/2]
	[varSet,docMidY,docHeight/2]
	[varSet,lix,min(docWidth,docHeight)-2]
	[varSet,DrawRadius,min([iGet,texture:inventory:width],[iGet,texture:inventory:height])]
	[varSet,DrawRadius,(int(lix/DrawRadius)/2)*DrawRadius]
	[if,DrawRadius=0,[varSet,DrawRadius,lix]]
	[varSet,FadeWidth,[iGet,zscript:fade-inwidth]*DrawRadius/100]
	[if,lVmeth<0,
		[RoutineCall,NewLayer1]
		[RoutineCall,DrawTexture,ThisTexture,docMidX,docMidY]
	, // else
		[routineCall,[var,MethodNameV(lVmeth)]]
	] // end if
	[if,lHmeth<0,,[routineCall,[var,MethodNameH(lHmeth)]]]
	[loop,4,
		[if,(GradPos != 0),[routineCall,RotateGrad]]
	]
,lHmeth,lVmeth] // end MakeItHappen

[RoutineDef,InitCloner,
	[iPress,tool:clonerbrush]
	[iPress,tool:modifiers:layersmode]
	[iUnPress,tool:modifiers:retaincenter]
	[iPress,draw:rgb]
	[iPress,draw:zadd][iUnPress,draw:zadd]
	[iPress,stroke:dragRect]
	[iSet,alpha:itemInfo,27]
	[varSet,ClonerInited,tool:itemInfo]
] // end InitCloner routine

[RoutineDef,DrawTexture,
	[iPress,tool:simpleBrush]
	[iPress,stroke:dragRect]
	[iPress,draw:rgb][iPress,draw:zadd]
	[iSet,draw:rgbIntensity,100]
	[iSet,alpha:itemInfo,0]
	[iSet,alpha:noise,0]
	[iSet,texture:itemInfo,lTexture]
	[iSet,material:itemInfo,0]
	[canvasClick,lx,ly,lx,ly+(DrawRadius*1.414)]
	[transformSet,lx,ly,[pixolPick,1,lx,ly],DrawRadius,DrawRadius,100]
,lTexture,lx,ly] // end DrawTexture routine

[RoutineDef,RotateGrad,
	[iSet,alpha:itemInfo,27]
	[iPress,alpha:rotate90]
	[varInc,GradPos]
	[if,(GradPos=4),[varSet,GradPos,0]]
] // end RotateGrad routine

[RoutineDef,CloneGrad,
	[if,(ClonerInited=0),[routineCall,InitCloner]]
	[iSet,tool:itemInfo,ClonerInited]
	[if,(GradPos != lPos),
		[varSet,ilPos,lPos]
		[if,(lPos < GradPos),[varAdd,ilPos,4]]
		[loop,(ilPos-GradPos),
			[routineCall,RotateGrad]
		] // end loop
	] // end if
	[varSet,lCloneWidth,(DrawRadius*abs(PosTransY(lPos))) + (FadeWidth*abs(PosTransX(lPos)))]
	[varSet,lCloneHeight,(DrawRadius*abs(PosTransX(lPos))) + (FadeWidth*abs(PosTransY(lPos)))]
	[varSet,lCloneX,((DrawRadius-FadeWidth)*PosTransX(lPos))+docMidX]
	[varSet,lCloneY,((DrawRadius-FadeWidth)*PosTransY(lPos))+docMidY]
	[varSet,lCloneZ,[pixolPick,1,docMidX,docMidY]]
	
	[iKeyPress,CTRL,[canvasClick,lCloneX,lCloneY]]
	[canvasClick,lCloneX,lCloneY,lCloneX,lCloneY+(lCloneHeight*1.414)]
	[transformSet,lCloneX,lCloneY,lCloneZ,lCloneWidth,lCloneHeight,100]
,lPos] // end CloneGrad routine

[RoutineDef,PaintGrad,
	[iPress,tool:simpleBrush]
	[iPress,draw:zadd][iUnPress,draw:zadd]
	[iSet,texture:itemInfo,0]
	[iSet,alpha:itemInfo,27]
	[if,(GradPos != lPos),
		[varSet,ilPos,lPos]
		[if,(lPos < GradPos),[varAdd,ilPos,4]]
		[loop,(ilPos-GradPos),
			[routineCall,RotateGrad]
		] // end loop
	] // end if
	[varSet,lCloneWidth,(DrawRadius*abs(PosTransY(lPos))) + (FadeWidth*abs(PosTransX(lPos)))]
	[varSet,lCloneHeight,(DrawRadius*abs(PosTransX(lPos))) + (FadeWidth*abs(PosTransY(lPos)))]
	[varSet,lCloneX,((DrawRadius-FadeWidth)*PosTransX(lPos))+docMidX]
	[varSet,lCloneY,((DrawRadius-FadeWidth)*PosTransY(lPos))+docMidY]
	[varSet,lCloneZ,[pixolPick,1,docMidX,docMidY]]
	
	[canvasClick,lCloneX,lCloneY,lCloneX,lCloneY+(lCloneHeight*1.414)]
	[transformSet,lCloneX,lCloneY,lCloneZ,lCloneWidth,lCloneHeight,100]
,lPos] // end PaintGrad routine

[RoutineDef,NewLayer1,
	[varSet,lix,3842]
	[loop,16,
		[if,[isDisabled,lix],
			[varSet,WorkLayer(0),lix]
			[loopExit]
		] // end if
		[varInc,lix]
	] // end loop
	[varDec,lix]
	[iPress,lix][iPress,lix][iKeyPress,SHIFT,[iClick,lix,3,3]]
	[iPress,layer:inventory:create]
] // end NewLayer1 routine

[RoutineDef,NewLayer2,
	[varSet,WorkLayer(1),WorkLayer(0)+1]
	[iPress,layer:inventory:create]
] // end NewLayer2 routine

[routineDef,StoreSettings,
	[varSet,SettingsData(0),tool:itemInfo]
	[varSet,SettingsData(10),texture:itemInfo]
	[iPress,tool:simpleBrush]
	[varSet,SettingsData(1),stroke:itemInfo]
	[varSet,SettingsData(2),alpha:itemInfo]
	[varSet,SettingsData(3),0]
	[varSet,lix,4356]
	[loop,3,
		[if,[iGet,lix],[varSet,SettingsData(3),lix]]
		[varInc,lix]
	]
	[varSet,SettingsData(4),0]
	[varSet,lix,4359]
	[loop,3,
		[if,([iGet,lix]),[varSet,SettingsData(4),lix]]
		[varInc,lix]
	]
	[varSet,SettingsData(5),draw:rgbintensity]
	[iPress,color:r]
	[varSet,SettingsData(6),[iGet,color:r]]
	[iPress,color:g]
	[varSet,SettingsData(7),[iGet,color:g]]
	[iPress,color:b]
	[varSet,SettingsData(8),[iGet,color:b]]
	[varSet,SettingsData(9),material:itemInfo]
	[iSet,texture:itemInfo,SettingsData(10)]
] // end routine StoreSettings

[routineDef,RecallSettings,
	[iPress,tool:simpleBrush]
	[iSet,stroke:itemInfo,SettingsData(1)]
	[iSet,alpha:itemInfo,SettingsData(2)]
	[if,(SettingsData(3)>0),[iPress,SettingsData(3)],[iPress,4356][iUnPress,4356]]
	[if,(SettingsData(4)>0),[iPress,SettingsData(4)],[iPress,4359][iUnPress,4359]]
	[iSet,draw:rgbIntensity,SettingsData(5)]
	[iColorSet,SettingsData(6),SettingsData(7),SettingsData(8)]
	[iSet,material:ItemInfo,SettingsData(9)]
	[iSet,tool:itemInfo,SettingsData(0)]
] // end RecallSettings

[routineDef,VerifyUndo,
	[if,[var,ShowMessage],
		[if,[MessageYesNo,"Okay to grab this image? (Press YES to grab, NO to remove)","Grab or Remove? (This cannot be undone)"],
			[RoutineCall,GrabTile]
			[varSet,VerifyResult,1]	
		] // end if
	, // else
		[RoutineCall,GrabTile]
		[varSet,VerifyResult,1]	
	] // end if
	[iKeyPress,SHIFT,[iPress,WorkLayer(0)]]
	[iKeyPress,13,[iPress,layer:inventory:delete]]		
	[if,(HybridTexture != 0),
		[iSet,texture:itemInfo,HybridTexture]
		[iPress,texture:inventory:remove]
		[varSet,HybridTexture,0]
	] // end if
	[routineCall,recallSettings]
	[iPress,3842][iUnPress,3842][iKeyPress,SHIFT,[iClick,3842,3,3]]
] // end VerifyUndo

[RoutineDef,MethodV1,
	[RoutineCall,NewLayer1]
	[RoutineCall,DrawTexture,ThisTexture,docMidX,docMidY]
	[iPress,layer:modifiers:flipv]
	[iPress,layer:inventory:dup]
	[iSet,layer:modifiers:displacez,-1]
	[iPress,layer:modifiers:flipv]
	[RoutineCall,cloneGrad,3]
	[iKeyPress,13,[iPress,layer:inventory:mrg]]
] // end MethodV1 routine
[RoutineDef,MethodH1,
	[iPress,layer:modifiers:fliph]
	[iPress,layer:inventory:dup]
	[iSet,layer:modifiers:displacez,-1]
	[iPress,layer:modifiers:fliph]
	[RoutineCall,cloneGrad,2]
	[iKeyPress,13,[iPress,layer:inventory:mrg]]
] // end MethodH1 routine

[RoutineDef,MethodV2,
	[RoutineCall,NewLayer1]
	[RoutineCall,DrawTexture,ThisTexture,docMidX,docMidY-DrawRadius]
	[RoutineCall,DrawTexture,ThisTexture,docMidX,docMidY+DrawRadius]
	[RoutineCall,NewLayer2]
	[routineCall,DrawTexture,ThisTexture,docMidX,docMidY]
	[iSet,layer:modifiers:displacez,-1]
	[routineCall,cloneGrad,1]
	[routineCall,cloneGrad,3]
	[iPress,WorkLayer(0)]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
] // end MethodV2 routine
[routineDef,MethodH2,
	[iPress,layer:inventory:dup]
	[iPress,layer:inventory:dup]
	[iSet,layer:modifiers:displacez,-1]
	[iUnPress,layer:modifiers:wrapmode]
	[iPress,WorkLayer(0)]
	[iSet,layer:modifiers:displaceh,-drawRadius]
	[iPress,[val,WorkLayer(0)+1]]
	[iSet,layer:modifiers:displaceh,drawRadius]
	[iKeyPress,13,[iPress,layer:inventory:mrg]]
	[iPress,layer:modifiers:wrapmode]
	[iPress,[val,WorkLayer(0)+1]]
	[routineCall,cloneGrad,0]
	[routineCall,cloneGrad,2]
	[iPress,WorkLayer(0)]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
] // end MethodH2 routine

[RoutineDef,MakeHybrid,
	[RoutineCall,NewLayer1]
	[RoutineCall,DrawTexture,SecondTexture,docMidX,docMidY-DrawRadius]
	[RoutineCall,DrawTexture,SecondTexture,docMidX,docMidY+DrawRadius]
	[RoutineCall,NewLayer2]
	[routineCall,DrawTexture,SecondTexture,docMidX,docMidY]
	[iSet,layer:modifiers:displacez,-1]
	[routineCall,cloneGrad,1]
	[routineCall,cloneGrad,3]
	[iPress,WorkLayer(0)]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
	[RoutineCall,GrabTile]
	[varSet,HybridTexture,texture:itemInfo]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
] // end MakeHybrid routine
[RoutineDef,MethodV3,
	[RoutineCall,MakeHybrid]
	[RoutineCall,NewLayer1]
	[routineCall,DrawTexture,HybridTexture,docMidX,docMidY]
	[RoutineCall,NewLayer2]
	[routineCall,DrawTexture,ThisTexture,docMidX,docMidY]
	[iSet,layer:modifiers:displacez,-1]
	[routineCall,cloneGrad,1]
	[routineCall,cloneGrad,3]
	[iPress,WorkLayer(0)]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
] // end MethodV3 routine
[routineDef,MethodH3,
	[if,HybridTexture=0,
		[varSet,lix,WorkLayer(0)]
		[RoutineCall,MakeHybrid]
		[varSet,WorkLayer(0),lix]
	] // end if
	[RoutineCall,NewLayer2]
	[RoutineCall,DrawTexture,HybridTexture,docMidX-DrawRadius,docMidY]
	[RoutineCall,DrawTexture,HybridTexture,docMidX+DrawRadius,docMidY]
	[iSet,layer:modifiers:displacez,1]
	[iPress,layer:inventory:movelayerup]
	[iPress,[val,WorkLayer(1)]]
	[if,[iGet,[val,WorkLayer(1)]],,[iPress,[val,WorkLayer(1)]]]
	[routineCall,cloneGrad,0]
	[routineCall,cloneGrad,2]
	[iPress,WorkLayer(0)]
	[iKeyPress,13,[iPress,layer:inventory:deletelayer]]
] // end MethodH3 routine

[RoutineDef,MethodV4,
	[RoutineCall,NewLayer1]
	[RoutineCall,DrawTexture,ThisTexture,docMidX,docMidY]
	[RoutineCall,PaintGrad,1]
	[RoutineCall,PaintGrad,3]
] // end MethodV4 routine
[RoutineDef,MethodH4,
	[RoutineCall,PaintGrad,0]
	[RoutineCall,PaintGrad,2]
] // end MethodH4 routine

[RoutineDef,GrabTile,
		[iPress,tool:mrgbzgrabber]
		[iUnPress,draw:zadd][iPress,draw:mrgb]
		[canvasClick,docMidX,docMidY,docMidX+drawRadius+1,docMidY+drawRadius+1]
] // end GrabTile